package 二分查找;

public class LeetCode367_有效的完全平方数 {
    public boolean isPerfectSquare(int num) {
        int left = 0, right = num;
        while (left <= right) {
            int mid = (right - left) / 2 + left;
            long square = (long) mid * mid;
            if (square < num) {
                left = mid + 1;
            } else if (square > num) {
                right = mid - 1;
            } else {
                return true;
            }
        }
        return false;
    }

//    int nums = 1;
//        while(num > 0) {
//        num -= nums;
//        nums += 2;
//    }
//        if(num == 0) {
//        return true;
//    }
//
//        return false;

}
